/*
 * @Author: qjb 
 *  文件资源
 * @Date: 2018-06-26  
 */
layui.use(['zlContext', 'form', 'upload'], function () {
	var $ = layui.$
		, form = layui.form
		, zlContext = layui.zlContext
		, upload = layui.upload
		, layer = layui.layer
		, zlConfig = layui.zlConfig
		, statusName = zlConfig.global.result.statusName
		, msgName = zlConfig.global.result.msgName
		, dataName = zlConfig.global.result.dataName
		, ERROR = zlConfig.global.result.errorState
		, OK = zlConfig.global.result.okState
		, form = layui.form;


		console.log($('#TOUX'));
	//设置我的资料
	form.on('submit(btnSave)', function (obj) {
		var param = obj.field;
		zlContext.post(layui.cache['contentPath'] + '/admin/coreuser/modifycheckbyflag?flag=1', param, function (result) {
			if (result[statusName] == OK) {
				zlContext.successMsg("个人基本资料修改成功！");
				$('#TOUX',parent.document).attr('src' ,layui.cache['contentPath'] + param.TOUX)
			}
			else {
				zlContext.errorMsg(result[msgName]);
			}
		});
		return false;
	});

	//上传头像
	var avatarSrc = $('#imgPrieviewPic');
	upload.render({
		url: layui.cache['contentPath'] + '/admin/coreuser/upload/'
		, elem: '#btnUploadfile'
		, accept:'images'
		, acceptMime:'image/*'
		, done: function (res) {
			if (res.state == OK) {
				avatarSrc.prop('src',layui.cache['contentPath'] +res.obj[0].newFileName);
				$('input[name="TOUX"]').val(res.obj[0].newFileName);
			} else {
				layer.msg(res.msg, { icon: 5 });
			}
		}
	});

	// param = JSON.stringify({ rwid: 'xxxx' });
	// zlContext.post(layui.cache['contentPath'] + 'admin/coreuser/query', param, function (result) {
	// 	if (result[statusName] == OK) {


	// 	}
	// 	else {
	// 		zlContext.errorMsg(result[msgName]);
	// 	}
	// });
	$('#rein').on('click',function(){
		avatarSrc.prop('src','');
		$('input[name="TOUX"]').val('');
		$('input[name="OBJNAME"]').val('');
		$('input[name="XINGB"][value="1"]').attr('checked',true);
		$('input[name="XINGB"][value="0"]').attr('checked',false);
		$('input[name="SHOUJH"]').val('');
		$('input[name="YOUX"]').val('');
		form.render();
		return false;	
	});
	var uservo = zlContext.getCurrentUser().userCursor;
	$('input[name="RWID"]').val(uservo.RWID);
	$('input[name="MNGDEPIDS"]').val(uservo.MNGDEPIDS);
	$('input[name="ROLEIDS"]').val(uservo.ROLEIDS);
	avatarSrc.prop('src',layui.cache['contentPath'] +uservo.TOUX);
	zlContext.autoFill('#frmGridUser',uservo);
});